﻿@using NextAction.Domain.Concrete
@using NextAction.Domain.Entities
@using NextAction.WebUI.Models

@model NextAction.WebUI.Models.CollectionViewModel

@{
    ViewBag.Title = "Collection";
}

@if (false)
{
    <script src="~/Scripts/jquery-1.7-vsdoc.js" type="text/javascript"></script>
    <script src="~/Scripts/next.action-1.0.js" type="text/javascript"></script>
}

<script type="text/javascript">
    $(function () {
        IndexCollectionView.enableClickOnBuckets();
        IndexCollectionView.enableTaskDropping();
    })

    function IndexCollectionView() {
    }

    IndexCollectionView.enableClickOnBuckets = function() {
        $("div.box_body li").click(function () {
            $("li.selected").removeClass("selected");
            $(this).addClass("selected");
            IndexCollectionView.loadTasksForSelectedBucket();
        })
    }

    IndexCollectionView.enableTaskDropping = function() {
        $('li.task_filter').droppable({
            accept: '.task_row',
            hoverClass: 'dropover',
            drop: function (event, ui) {
                var taskID = $(ui.draggable).attr('task_id');
                var bucketType = $(this).attr('bucket_type');
                GtdRepository.moveTask(taskID, bucketType, function () {
                    IndexCollectionView.loadTasksForSelectedBucket();
                });
            }
        });
    }

    IndexCollectionView.loadTasksForSelectedBucket = function () {
        var selectedBucketType = $("li.selected").attr('bucket_type');
        GtdRepository.loadTaskList('#task_list', selectedBucketType, function () {
            IndexTaskView.refreshTaskList();
            IndexCollectionView.refreshBucketsCount();
        });
    }

    IndexCollectionView.refreshBucketsCount = function () {
        GtdRepository.getBucketSizes(function (bucketSizes) {
            $('a#bucket_size_inbox').text(' (' + bucketSizes.Inbox + ')');
            $('a#bucket_size_next').text(' (' + bucketSizes.Next + ')');
            $('a#bucket_size_today').text(' (' + bucketSizes.Today + ')');
            $('a#bucket_size_tomorrow').text(' (' + bucketSizes.Tomorrow + ')');
            $('a#bucket_size_scheduled').text(' (' + bucketSizes.Scheduled + ')');
            $('a#bucket_size_wait').text(' (' + bucketSizes.Wait + ')');
            $('a#bucket_size_someday').text(' (' + bucketSizes.Someday + ')');
        });
    }

</script>

<div class="left" id="main_left">
    <div id="sidebar">

        <div class="box">
	        <div class="box_title">Buckets</div>
		    <div class="box_body">
			    <ul> 
				    <li class="selected task_filter" bucket_type="Inbox">
                        <div>
                            <a>Inbox</a> <a id="bucket_size_inbox"> (@Model.BucketSizes[BucketType.Inbox].ToString())</a>
                        </div>
                    </li>
   				    <li class="task_filter" bucket_type="Next">
                        <div>
                            <a>Next</a> <a id="bucket_size_next"> (@Model.BucketSizes[BucketType.Next].ToString())</a>
                        </div>
                    </li>
   				    <li class="task_filter" bucket_type="Today">
                        <div>
                            <a>Today</a> <a id="bucket_size_today"> (@Model.BucketSizes[BucketType.Today].ToString())</a>
                        </div>
                    </li>
 				    <li class="task_filter" bucket_type="Tomorrow">
                        <div>
                            <a>Tomorrow</a> <a id="bucket_size_tomorrow"> (@Model.BucketSizes[BucketType.Tomorrow].ToString())</a>
                        </div>
                    </li>
   				    <li class="task_filter" bucket_type="Scheduled">
                        <div>
                            <a>Scheduled</a> <a id="bucket_size_scheduled"> (@Model.BucketSizes[BucketType.Scheduled].ToString())</a>
                        </div>
                    </li>
   				    <li class="task_filter" bucket_type="Wait">
                        <div>
                            <a>Waits</a> <a id="bucket_size_wait"> (@Model.BucketSizes[BucketType.Wait].ToString())</a>
                        </div>
                    </li>
   				    <li class="task_filter" bucket_type="Someday">
                        <div>
                           <a>Someday</a> <a id="bucket_size_someday"> (@Model.BucketSizes[BucketType.Someday].ToString())</a>
                        </div>
                    </li>
			    </ul>
		    </div>
    	    <div class="box_bottom"></div>
	    </div>
    </div>
 </div>

<div id="main_right" class="left">
    <div id="main_right_content">
        @{  
            Html.RenderAction("Index", "Task", new { BucketType = BucketType.Inbox }); 
        }
    </div>
</div>




